/**
 * 
 */
package unseen.labs.games.mysnake.view;

import unseen.labs.games.mysnake.view.renderer.GenericRenderer;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Debug;
import android.view.MotionEvent;

/**
 * @author PERRAUDIN Steven <sperraudin@neotilus.com>
 *
 * @date 4 juin 2010
 */
public class GenericView extends GLSurfaceView{
	
	private GenericRenderer _renderer;
	
	private float _oldX = 0;	
    private float _oldY = 0;
    private float _x = 0;	
    private float _y = 0;
    
	public GenericView(Context context){
		super(context);
		_renderer = new GenericRenderer();
		setRenderer(_renderer);
	}
	
	public boolean onTouchEvent(final MotionEvent event) {		
		
		if(!_renderer._ingame){
			_renderer.restartGame();
		}

        if (event.getAction() == MotionEvent.ACTION_MOVE) {
        	
            
            queueEvent(new Runnable() {
                public void run() {

                	_renderer.setRacketPosition(_oldX, _x);
                	_x = event.getX();
                    _y = event.getY();
                }
            });
            
            _oldX = event.getX();
            _oldY = event.getY();
            
        }
        return true;
    }

}
